home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
22
/
2
/
DISK2220.ZIP
/
SCREDIT2.EXE
/
SCREDIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-05
|
58KB
|
2,719 lines
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>
#include <bios.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <alloc.h>
#include "scredit.h"
#include "#defines.C"
#ifdef MOUSE
#include "ScrMouse.c"
#endif
typedef union
{
int ch;
struct{
unsigned char lsb;
unsigned char msb;
} byte;
}keyindef;
keyindef shiftstat;
struct {
char s_name [17];
unsigned char s_number;
int s_recordnumber;
int s_fieldsrecno;
int s_rangerecno;
unsigned char s_first;
unsigned char s_count;
unsigned char s_compiledind;
}s_curr;
s_rec_def *s_indx, *s_record, *s_field;
int long s_cursorold;
FILE *s_file, *s_work;
enum s_cursors s_cursor;
unsigned char
s_tabatendoffield,
s_clearifnotrightarrow,
s_clearnotright,
s_sound,
s_helpsound,
s_errorsound,
s_usersound,
s_showstatus,
s_changescreen,
s_force_editmask,
S_PosLastChar,
s_autohelp,
s_autovalidate,
s_enterastab,
s_delayscreen,
s_delayed,
s_fkey,
s_f1,
s_f2,
s_f3,
s_f4,
s_f5,
s_f6,
s_f7,
s_f8,
s_f9,
s_f10,
s_f11,
s_f12,
s_enter,
s_bksp,
s_home,
s_up,
s_pgup,
s_left,
s_right,
s_end,
s_down,
s_pgdn,
s_ins,
s_del,
s_tab,
s_shift,
s_leftshift,
s_rightshift,
s_insertmode,
s_insertkey,
s_deletekey,
s_backspace,
s_leftarrow,
s_rightarrow,
s_scrolllock,
s_caps,
s_numlock,
s_alt,
s_ctrl,
s_esc,
s_helpbg,
s_helpfg,
s_errorbg,
s_errorfg,
s_userbg,
s_userfg,
s_stbg,
s_stfg,
s_stlabelbg,
s_stlabelfg,
s_stlabelcolor,
s_stcolor,
s_ch,
S_FirstTime = 1,
s_sound_hold,
s_mono,
s_upcase,
s_validate_finished,
s_screenvalid,
s_wait,
s_nextline,
s_reverse,
s_skip,
s_matched,
s_min_max_loaded,
s_endofline,
s_insideif,
s_bw,
s_dupfields,
s_setdupefields,
s_entrytype,
s_disptype,
s_duptype,
s_ftype;
char
s_alphamaskmsg[81],
s_numericmaskmsg[81],
s_numericfieldmsg[81],
s_alphafieldmsg[81],
s_usermask [81],
s_userhelp [81],
s_usermsg [81],
s_curstr [81],
s_editstrhold[81],
s_compmin [81],
s_compmax [81],
s_compfield [81],
s_opcode [81],
s_opcode1 [81],
s_workstr [81],
s_msg [81],
s_editstr [81],
s_blanks [81],
s_newstr [81],
s_padding [81],
s_workattrib [81],
s_normattrib [81],
s_initialvalue[81],
s_errormsg [81],
s_editmask [81],
s_editmasktypes[7],
s_autohelpmsg [81],
s_stline [41],
s_stattrib [41],
s_ins_str [2];
int
s_enterafterfield,
s_firstfield,
s_point,
s_freq,
s_dur,
s_errorfreq,
s_errordur,
s_helpfreq,
s_helpdur,
s_userfreq,
s_userdur,
s_vrec,
s_recno,
s_validateline,
s_validatefield,
s_helppos,
s_nextpos,
s_lastpos,
s_str_pos,
s_attrib,
s_messbg,
s_messfg,
s_num,
s_f_key,
s_direction,
s_decimal,
s_prevfield,
s_fieldnum,
s_sub,
s_currline,
s_nextrec;
double
S_Round [8] = {.5,.5,.05,.005,.0005,.00005,.000005,.0000005},
s_numeric,
s_compmin_Numeric,
s_compmax_Numeric;
unsigned char s_fileOpen;
int s_fieldPtr [128],
CursorDirection,
FirstPosition,
LastPosition;
char *S_BuffPtr [128];
char *S_WorkArea;
unsigned char S_ClearLine;
unsigned char S_TextAttr;
void S_Get_Field_Value(int);
void S_PreEdit(int,int);
int s_pos(char *s1,char *s2)
{
unsigned long X,Y,Z;
X=0;
Y=0;
Z=0;
while (s1[X]!=0)
{
Z=X;
while (s1[Z]==s2[Y])
{
if (s1[Z+Y]==s2[Y])
{
Y++;
if (s2[Y]==0)
return X;
}
else
{
Z++;
Y=0;
}
}
X++;
}
return -1;
}
void s_delete(char *string1, int startpos,int count)
{
unsigned long x,y,z;
char s1 [81];
strcpy(s1,string1);
if (startpos < strlen(s1))
{
z = startpos + count;
if (z > strlen(s1)) count = strlen(s1)-startpos;
string1[startpos]=0;
strcat(string1,(char*)&s1[startpos + count]);
}
}
void s_insert(char *string1,char *string2,int insertpoint,int maxlength)
{
unsigned long X,Y,Z;
char s1 [162], s2 [81], s3 [81];
if ((insertpoint > -1) && (insertpoint <= strlen(string1)))
{
strcpy(s3,(char *)&string1[insertpoint]);
string1[insertpoint]=0;
strcpy(s1,string1);
strcpy(s2,string2);
strcat(s1,s2);
strcat(s1,s3);
s1[maxlength]=0;
strcpy(string1,s1);
}
}
int s_strlen(char *target_string)
{
int x,y,z;
x=strlen(target_string);
while ((target_string[x-1]<33)&&(x>=0)) x--;
if (x>-1) x++;
return x;
}
void s_resetkeyflags()
{
s_f1=0;
s_f2=0;
s_f3=0;
s_f4=0;
s_f5=0;
s_f6=0;
s_f7=0;
s_f8=0;
s_f9=0;
s_f10=0;
s_f11=0;
s_f12=0;
s_home=0;
s_end=0;
s_pgup=0;
s_pgdn=0;
s_left=0;
s_right=0;
s_up=0;
s_down=0;
s_del=0;
s_tab=0;
s_bksp=0;
s_esc=0;
s_ctrl=0;
s_enter=0;
s_fkey=0;
s_alt=0;
s_shift=0;
s_ins=0;
s_numlock=0;
s_insertkey=0;
s_deletekey=0;
s_backspace=0;
s_leftarrow=0;
s_rightarrow=0;
s_nextpos=0;
s_lastpos=0;
}
unsigned char S_SetColor(unsigned char Bg, unsigned char Fg)
{
unsigned char color;
color = (Fg>15)? ((Bg-16)*16)+Fg+127:(Bg*16)+Fg;
return color;
}
void s_getfieldtype(unsigned char FType)
{
s_duptype = 0;
s_entrytype = 0;
s_disptype = 0;
if (FType<10)
{
s_ftype = FType;
s_entrytype = 1;
}
if ((FType >=10)&&(FType<=19))
{
s_ftype = FType % 10;
s_duptype = 1;
}
if ((FType >=90)&&(FType<=99))
{
s_ftype = FType % 90;
s_disptype = 1;
}
if ((FType >=100)&&(FType<=109))
{
s_ftype = FType % 100;
s_disptype = 1;
s_duptype = 1;
}
}
void s_setcursor(unsigned char S)
{
union REGS in,out;
in.h.ah = 1;
in.h.bh = 0;
if (S==0) in.x.cx = 4096;
if ((S==1)||(S==3)) in.x.cx = 15;
if ((S==2)||(S==4)) in.x.cx = s_cursorold;
if (S==5) in.h.ah = 3;
int86(0x10,&in,&out);
if (S==5) s_cursorold = out.x.cx;
}
void s_init()
{
struct text_info r;
int loop1;
s_cursorold = 1543;
if (S_FirstTime)
{
#if defined (__MEDIUM__)
s_indx = (s_rec_def *) malloc (sizeof(*s_indx));
s_record = (s_rec_def *) malloc (sizeof(*s_record));
s_field = (s_rec_def *) malloc (sizeof(*s_field));
#else
s_indx = (s_rec_def *) farmalloc (sizeof(*s_indx));
s_record = (s_rec_def *) farmalloc (sizeof(*s_record));
s_field = (s_rec_def *) farmalloc (sizeof(*s_field));
#endif
s_setcursor (S_GETCURSOR);
S_FirstTime = 0;
#ifdef MOUSE
s_initmouse();
#endif
}
s_setcursor(S_OFF);
s_cursor=S_INVERSENORMAL;
s_tabatendoffield = 1;
s_enterafterfield = -1;
s_clearifnotrightarrow = 0;
s_usermask[0]=0;
s_userhelp[0]=0;
s_vrec=0;
s_stbg=0;
s_stfg=2;
s_stlabelbg=7;
s_stlabelfg=0;
s_messbg=4;
s_messfg=15;
s_msg[0]=0;
s_errorbg=4;
s_errorfg=15;
s_userbg=0;
s_userfg=14;
s_helpbg=7;
s_helpfg=0;
s_editmask[0]=0;
s_autohelpmsg [0]=0;
s_force_editmask=0;
s_autohelp=0;
s_autovalidate=0;
s_sound=1;
s_freq=300;
s_dur=100;
s_helpsound=1;
s_helpfreq=300;
s_helpdur=100;
s_usersound=1;
s_userfreq=300;
s_userdur=100;
s_errorsound=1;
s_errorfreq=300;
s_errordur=100;
S_PosLastChar=0;
s_changescreen=1;
s_ch=0;
s_point=-1;
s_direction=1;
s_f_key=0;
s_recno=0;
s_validateline=0;
s_validatefield=-1;
s_insertkey=0;
s_deletekey=0;
s_backspace=0;
s_leftarrow=0;
s_rightarrow=0;
s_enterastab=0;
s_delayscreen=0;
s_delayed=0;
s_fileOpen=0;
S_ClearLine=0;
memset(s_msg,0,81);
memset(s_blanks,32,80);
S_WorkArea = NULL;
for (loop1=0;loop1<128;loop1++) S_BuffPtr[loop1]=NULL;
s_blanks[80]=0;
strcpy(s_stline,"[Insert] [Caps] [Num Lock] [Scroll Lock]");
strcpy(s_numericmaskmsg ," Enter numbers only ('0' thru '9') here.");
strcpy(s_alphamaskmsg ," Enter alpha only ('a'-'z','A'-'Z') only.");
strcpy(s_numericfieldmsg," Enter numeric data here ('-','.','0'-'9') only.");
strcpy(s_alphafieldmsg ," Enter alpha only (BLANK,'a'-'z','A'-'Z') only.");
strcpy(s_editmasktypes,"@2#3$4");
strcpy(s_normattrib,s_msg);
strcpy(s_newstr,s_msg);
strcpy(s_padding,s_msg);
gettextinfo(&r);
S_TextAttr = r.attribute;
textmode(r.currmode);
if (r.currmode==MONO) s_mono = 1; else s_mono = 0;
if ((!s_indx)||(!s_record)||(!s_field))
{
cprintf("Unable to allocate far memory..\r\n");
exit (1);
}
s_resetkeyflags();
}
void s_closescreenfile()
{
if (S_FirstTime) s_init();
if (s_fileOpen)
{
fclose(s_file);
s_setcursor(S_NORMAL);
}
if (S_TextAttr) textattr(S_TextAttr);
}
void s_loadscreenIndex()
{
int loop1,loop2,loop3;
if (fseek(s_file,0L,0) != 0)
{
puts("seek failed ");
exit (1);
}
if (fread(s_indx,sizeof(*s_indx),1,s_file) < 1)
{
puts("reload index failed ");
exit (1);
}
for (loop1=0;loop1 < s_indx->A.s_sfiled;loop1++)
{
loop2 = s_indx->A.s_name[loop1][0];
for (loop3=1;loop3 < (loop2+2);loop3++)
s_indx->A.s_name[loop1][loop3-1]=s_indx->A.s_name[loop1][loop3];
s_indx->A.s_name[loop1][loop2]=0;
}
s_vrec = -999;
}
void s_openscreenfile (char *scrfilename)
{
int loop1,loop2,loop3;
if (S_FirstTime) s_init();
if (s_fileOpen) s_closescreenfile();
loop2 = 0;
loop1 = 0;
while (scrfilename[loop1] != 0)
{
if (scrfilename[loop1++] == '.') loop2 = 1;
}
if (!loop2) strcat(scrfilename,".Scr");
s_fileOpen = 1;
if ((s_file = fopen(scrfilename,"r+b")) == NULL)
{
cprintf("open up of %s failed\r\n",scrfilename);
exit (1);
}
s_loadscreenIndex();
}
void s_beep(int t,int l)
{
if (s_sound > 0)
{
sound(t);
delay(l);
nosound();
}
}
void s_write (int Row, int Col, int Len,char *Source, char *Attribs)
{
int Ptr;
for (Ptr=0;Ptr<=Len;Ptr++)
{
s_record->B.s_workarray[Ptr][0]=Source[Ptr];
s_record->B.s_workarray[Ptr][1]=Attribs[Ptr];
}
puttext(Col,Row,Col+Len,Row,(char *)&s_record->B.s_workarray[0][0]);
setmem(s_normattrib,sizeof(s_normattrib),0);
/*
s_putscrmem(Row,Col,(Len*2),(char *)&s_record->B.s_workarray[0][0]);
for (Ptr=1;Ptr<81;Ptr++) s_normattrib[Ptr]=0;
*/
}
void s_displaymessage(int Bg,int Fg,char *Msg)
{
int Msg_Len,W,X,Y;
if (S_FirstTime) s_init();
strcpy(s_padding,s_blanks);
strcpy(s_workattrib,s_blanks);
Msg_Len = strlen(Msg);
Y = (80 - Msg_Len)/2;
W = 0;
for (X=0;X<80;X++)
{
if (X<Y) s_workattrib[X] = 2;
else
if (X>((Y+Msg_Len)-1)) s_workattrib[X] = 2;
else
{
s_workattrib[X]=(Bg*16)+Fg;
s_padding [X]=Msg[W];
W++;
}
}
if (strlen(Msg)>0) s_beep(s_freq,s_dur);
s_write(25,1,80,s_padding,s_workattrib);
s_msg[0]=0;
}
void S_Store_Buf_Loc(char *ScrName, char *ScrBuff)
{
int X,Y,Z;
if (S_FirstTime) s_init();
s_loadscreenIndex();
for (X=0;X<s_indx->A.s_sfiled;X++)
{
if (strcmp(strupr(ScrName),strupr(s_indx->A.s_name[X]))==0)
{
S_BuffPtr [X] = ScrBuff;
break;
}
}
}
void s_loadscreen(char *ScrName)
{
int A,B,T,X,Y,Z;
int RR;
long rec;
if (S_FirstTime) s_init();
if (s_fileOpen)
{
s_loadscreenIndex();
s_num = -1;
for (X=0;X<s_indx->A.s_sfiled;X++)
{
if (strcmp(strupr(ScrName),strupr(s_indx->A.s_name[X]))==0)
{
s_num = X;
break;
}
}
s_msg[0]=0;
if (S_BuffPtr[s_num]==NULL)
strcpy(s_msg,"< > Buffer has not been initialized");
if (s_num==-1)
strcpy(s_msg,"< > has not been found");
if (s_indx->A.s_compiledind[s_num]==0)
strcpy(s_msg,"< > has not been compiled");
}
else
strcpy(s_msg,"< > has not been opened.");
if (s_msg[0]>0)
{
Y=1;
for (X=0;ScrName[X]!=NULL;X++) s_msg[Y++]=ScrName[X];
s_displaymessage(s_messbg,s_messfg,s_msg);
s_closescreenfile();
exit(1);
}
S_WorkArea = S_BuffPtr[s_num];
rec = (long) (s_indx->A.s_recordnumber[s_num])*sizeof(*s_record);
fseek(s_file,rec,0);
fread(s_record,sizeof(*s_record),1,s_file);
s_firstfield = 0;
if (s_indx->A.s_fieldsrecno[s_num])
{
if (s_changescreen)
{
rec = (long)(s_indx->A.s_fieldsrecno[s_num])*sizeof(*s_record);
fseek(s_file,rec,0);
fread(s_field,sizeof(*s_field),1,s_file);
}
s_firstfield = (s_indx->A.s_first[s_num])-1;
s_point = 0;
for (X=0;X<s_indx->A.s_count[s_num];X++)
{
Y = s_field->C.s_fieldname[X][0];
s_getfieldtype(s_field->C.s_type[X]);
movmem(&s_field->C.s_fieldname[X][1],&s_field->C.s_fieldname[X][0],16);
s_field->C.s_fieldname[X][Y]=0;
s_fieldPtr[X] = s_point;
if (s_ftype > 7)
s_point = s_point + s_field->C.s_len[X]+1;
else
s_point = s_point + sizeof((double)0);
A = ((s_field->C.s_col[X]-1)+s_field->C.s_len[X])*2;
B = (s_field->C.s_row[X]-1)*160;
for (Z=((s_field->C.s_col[X]-1)*2);Z<A;Z+=2)
s_record->B.s_video[B+Z]=32;
if (s_record->B.s_video[B+Z]==']')
s_record->B.s_video[B+Z]=32;
}
}
if (s_changescreen)
{
if (s_delayscreen)
{
s_delayed = 1;
s_delayscreen = 0;
}
else
puttext(1,1,80,24,&s_record->B.s_video[0]);
s_point = s_firstfield;
}
else
s_changescreen = 1;
strcpy(s_curr.s_name,s_indx->A.s_name[s_num]);
s_curr.s_number = s_indx->A.s_number [s_num];
s_curr.s_recordnumber = s_indx->A.s_recordnumber[s_num];
s_curr.s_fieldsrecno = s_indx->A.s_fieldsrecno [s_num];
s_curr.s_rangerecno = s_indx->A.s_rangerecno [s_num];
s_curr.s_first = s_indx->A.s_first [s_num];
s_curr.s_count = s_indx->A.s_count [s_num];
s_curr.s_compiledind = s_indx->A.s_compiledind [s_num];
}
void s_displayscreenfield(int R,int C,int T,int L,int DL,
int DF,int DB,int NF,int NB,char *S)
{
int Attr,x,y,z,l;
char Wk[80];
double *Dbl;
unsigned char BackColor, ForColor;
if (S_FirstTime) s_init();
Wk[0]=0;
strcpy(s_editstr,S);
DL = strlen(s_editstr);
if (DL > L)
{
DL = L;
s_editstr[L]=0;
}
if (DL>0)
Attr = (DB * 16) + DF;
else
Attr = (NB * 16) + NF;
setmem(s_normattrib,80,Attr);
movmem(&s_blanks,&s_padding,80);
l = (L - strlen(s_editstr));
s_padding[l]=0;
if ((T > 89)&&(T<98)) T-=89;
if (T<8)
{
strcpy(Wk,s_padding);
strcat(Wk,s_editstr);
}
else
{
strcat(Wk,s_editstr);
strcat(Wk,s_padding);
}
s_write(R,C,L-1,Wk,s_normattrib);
}
void S_FillScreen()
{
int Sign,DecPos,s_prevfield,Screen_Point,p,x,y,z,C;
unsigned char WorkAttrib;
double dbl_work, rounding, *Dbl;
s_prevfield = s_point;
s_point = 0;
while (s_point < s_curr.s_count)
{
s_getfieldtype(s_field->C.s_type[s_point]);
s_decimal = s_ftype;
if (s_decimal > 7)
{
strcpy(s_editstr,(char*)&S_WorkArea[(int)s_fieldPtr[s_point]]);
s_field->C.s_datalen[s_point] = strlen(s_editstr);
}
else
{
dbl_work = *((double *)(S_WorkArea+s_fieldPtr[s_point]));
if (dbl_work!=0.0)
{
rounding = (dbl_work<0)?(0-S_Round[s_decimal]):S_Round[s_decimal];
strcpy(s_editstr,ecvt((dbl_work+rounding),20,&DecPos,&Sign));
while (DecPos<1)
{
s_insert(s_editstr,"0",0,20);
DecPos++;
}
s_insert(s_editstr,".",DecPos,80);
while (s_editstr[0]=='0') s_delete(s_editstr,0,1);
if (Sign) s_insert(s_editstr,"-",0,80);
}
else
strcpy(s_editstr,".000000");
s_editstr[(s_pos(s_editstr,".")+s_decimal)]=0;
if (s_editstr[0]==0)
{
s_editstr[0]='0';
s_editstr[1]=0;
}
x = strlen(s_editstr);
y = x - s_field->C.s_len[s_point];
if (y>0)
while (y--)
{
s_delete(s_editstr,0,1);
x--;
}
s_field->C.s_datalen[s_point] = x;
}
Screen_Point = ((s_field->C.s_row[s_point]-1)*160)
+ ((s_field->C.s_col[s_point]-1)*2);
if (s_field->C.s_datalen[s_point]>0)
WorkAttrib = (s_field->C.s_displaybg[s_point] * 16)
+ s_field->C.s_displayfg[s_point];
else
WorkAttrib = (s_field->C.s_normalbg[s_point] * 16)
+ s_field->C.s_normalfg[s_point];
p=0;
x=((s_field->C.s_len[s_point]))*2;
y=(s_field->C.s_datalen[s_point])*2;
if (s_decimal > 7)
{
C=0;
while (C<x)
{
s_record->B.s_video[Screen_Point+C]=(C<=y)? s_editstr[p++]:32;
C++;
s_record->B.s_video[Screen_Point+C]= WorkAttrib;
C++;
}
}
else
{
z=(x-y)-4;
C=0;
while (C<x)
{
s_record->B.s_video[Screen_Point+C]= (C>z)?s_editstr[p++]:32;
C++;
s_record->B.s_video[Screen_Point+C]= WorkAttrib;
C++;
}
}
s_point++;
}
puttext(1,1,80,24,&s_record->B.s_video[0]);
s_point = s_prevfield;
}
void S_GetKey()
{
int C_nt;
unsigned char Two_Keys, Toggle,KeyDetected;
char ch;
typedef union
{
int ch;
struct{
unsigned char lsb;
unsigned char msb;
} byte;
}keyindef;
keyindef keyin;
keyindef shiftstat;
s_resetkeyflags();
if (s_errormsg[0]!=0)
{
s_freq = s_errorfreq;
s_dur = s_errordur;
s_sound = s_errorsound;
s_messbg = s_errorbg;
s_messfg = s_errorfg;
movmem(s_errormsg,s_msg,81);
s_errormsg[0]=0;
}
else
if (s_usermsg[0]!=0)
{
s_freq = s_userfreq;
s_dur = s_userdur;
s_sound = s_usersound;
s_messbg = s_userbg;
s_messfg = s_userfg;
movmem(s_usermsg,s_msg,81);
s_usermsg[0]=0;
}
else
if (s_autohelpmsg[0]!=0)
{
s_freq = s_helpfreq;
s_dur = s_helpdur;
s_sound = s_helpsound;
s_messbg = s_helpbg;
s_messfg = s_helpfg;
movmem(s_autohelpmsg,s_msg,81);
s_autohelpmsg[0]=0;
};
if (s_msg[0]!=0)
{
s_wait = 1;
s_displaymessage(s_messbg,s_messfg,s_msg);
S_ClearLine = 1;
}
#ifdef MOUSE
if ((s_ms->mouseactive)&&(s_mousevisable)) s_restoremouse();
#endif
do
{
KeyDetected = 0;
keyin.ch = 0;
#ifdef MOUSE
while ((!KeyDetected)&&(!s_ms->mouseevent))
#else
while (!KeyDetected)
#endif
{
Toggle = 0;
Two_Keys = 0;
#ifdef MOUSE
while ((!s_ms->mouseevent)&&(!KeyDetected)&&(!Two_Keys)&&(!Toggle))
#else
while ((!KeyDetected)&&(!Two_Keys)&&(!Toggle))
#endif
{
shiftstat.ch = bioskey(2);
C_nt = 0;
if (shiftstat.byte.lsb & 1) C_nt++;
if (shiftstat.byte.lsb & 2) C_nt++;
if (shiftstat.byte.lsb & 4) C_nt++;
if (shiftstat.byte.lsb & 8) C_nt++;
if (C_nt > 1) Two_Keys = 1;
if (bioskey(1)!=0) KeyDetected = 1;
if (KeyDetected)
keyin.ch = bioskey(0);
s_rightshift = 0;
s_leftshift = 0;
s_shift = 0;
s_scrolllock = 0;
s_caps = 0;
s_insertmode = 0;
s_numlock = 0;
s_ctrl = 0;
s_alt = 0;
C_nt = 0;
if (shiftstat.byte.lsb & 1){s_rightshift = 1; C_nt++; s_shift = 1;}
if (shiftstat.byte.lsb & 2){s_leftshift = 1; C_nt++; s_shift = 1;}
if (shiftstat.byte.lsb & 4){s_ctrl = 1; C_nt++;}
if (shiftstat.byte.lsb & 8){s_alt = 1; C_nt++;}
if (shiftstat.byte.lsb & 16) s_scrolllock = 1;
if (shiftstat.byte.lsb & 32) s_numlock = 1;
if (shiftstat.byte.lsb & 64) s_caps = 1;
if (shiftstat.byte.lsb & 128) s_insertmode = 1;
if (Two_Keys)
{
keyin.ch= 0;
s_ch = 0;
s_fkey = 1;
goto Exit;
}
if ((s_showstatus)&&(!s_wait))
{
memset(s_stattrib,s_stcolor,40);
if (s_insertmode) memset(s_stattrib,s_stlabelcolor,8);
if (s_caps) memset(&s_stattrib[9],s_stlabelcolor,6);
if (s_numlock) memset(&s_stattrib[16],s_stlabelcolor,10);
if (s_scrolllock) memset(&s_stattrib[27],s_stlabelcolor,13);
setmem(s_padding,80,32);
setmem(s_workattrib,80,0);
memmove((char *)&s_padding[21],s_stline,40);
memmove((char *)&s_workattrib[21],s_stattrib,40);
s_write(25,1,80,s_padding,s_workattrib);
}
}
}
}
#ifdef MOUSE
while ((keyin.ch == 0)&&(!s_ms->mouseevent));
if ((s_ms->mouseactive)&&(s_mousevisable)) s_removemouse();
#else
while (keyin.ch == 0);
#endif
if (S_ClearLine)
{
s_wait = 0;
s_msg[0]=0;
S_ClearLine = 0;
s_displaymessage(s_messbg,s_messfg,s_msg);
}
#ifdef MOUSE
if (s_ms->mouseevent) {keyin.ch=0;goto Exit;}
#endif
if ((s_ctrl) && (keyin.byte.lsb > 0) && (keyin.byte.lsb < 29))
{
s_fkey = 1;
ch = keyin.byte.lsb + 64;
goto Exit;
}
ch = 0;
if (s_shift)
{
if (keyin.byte.lsb==255)
{
s_fkey = 1;
switch (keyin.byte.msb)
{
case 71: case 10: {s_home = 1; break;}
case 79: case 11: {s_end = 1; break;}
case 73: case 12: {s_pgup = 1; break;}
case 81: case 13: {s_pgdn = 1; break;}
case 75: case 7 : {s_left = 1; break;}
case 77: case 8 : {s_right= 1; break;}
case 72: case 6 : {s_up = 1; break;}
case 80: case 9 : {s_down = 1; break;}
case 82: case 2 : {s_ins = 1; break;}
case 83: case 4 : {s_del = 1; break;}
case 15 : {s_tab = 1; break;}
default :
s_fkey = 0;
}
}
else
{
s_fkey = 1;
switch (keyin.byte.msb)
{
case 71: {s_home = 1; break;}
case 79: {s_end = 1; break;}
case 73: {s_pgup = 1; break;}
case 81: {s_pgdn = 1; break;}
case 75: {s_left = 1; break;}
case 77: {s_right= 1; break;}
case 72: {s_up = 1; break;}
case 80: {s_down = 1; break;}
case 82: {s_ins = 1; break;}
case 83: {s_del = 1; break;}
case 15: {s_tab = 1; break;}
default: s_fkey = 0;
}
}
}
if ((keyin.byte.lsb == 0)&&(keyin.byte.msb>0))
{
s_fkey = 1;
switch (keyin.byte.msb)
{
case 59 : s_f1 = 1; break;
case 60 : s_f2 = 1; break;
case 61 : s_f3 = 1; break;
case 62 : s_f4 = 1; break;
case 63 : s_f5 = 1; break;
case 64 : s_f6 = 1; break;
case 65 : s_f7 = 1; break;
case 66 : s_f8 = 1; break;
case 67 : s_f9 = 1; break;
case 68 : s_f10 = 1; break;
case 133: s_f11 = 1; break;
case 134: s_f12 = 1; break;
case 84 : s_f1 = 1; break;
case 85 : s_f2 = 1; break;
case 86 : s_f3 = 1; break;
case 87 : s_f4 = 1; break;
case 88 : s_f5 = 1; break;
case 89 : s_f6 = 1; break;
case 90 : s_f7 = 1; break;
case 91 : s_f8 = 1; break;
case 92 : s_f9 = 1; break;
case 93 : s_f10 = 1; break;
case 135: s_f11 = 1; break;
case 136: s_f12 = 1; break;
case 94 : s_f1 = 1; break;
case 95 : s_f2 = 1; break;
case 96 : s_f3 = 1; break;
case 97 : s_f4 = 1; break;
case 98 : s_f5 = 1; break;
case 99 : s_f6 = 1; break;
case 100: s_f7 = 1; break;
case 101: s_f8 = 1; break;
case 102: s_f9 = 1; break;
case 103: s_f10 = 1; break;
case 137: s_f11 = 1; break;
case 138: s_f12 = 1; break;
case 104: s_f1 = 1; break;
case 105: s_f2 = 1; break;
case 106: s_f3 = 1; break;
case 107: s_f4 = 1; break;
case 108: s_f5 = 1; break;
case 109: s_f6 = 1; break;
case 110: s_f7 = 1; break;
case 111: s_f8 = 1; break;
case 112: s_f9 = 1; break;
case 113: s_f10 = 1; break;
case 139: s_f11 = 1; break;
case 140: s_f12 = 1; break;
case 71 : s_home = 1; break;
case 79 : s_end = 1; break;
case 73 : s_pgup = 1; break;
case 81 : s_pgdn = 1; break;
case 75 : s_left = 1; break;
case 77 : s_right= 1; break;
case 72 : s_up = 1; break;
case 80 : s_down = 1; break;
case 82 : s_ins = 1; break;
case 83 : s_del = 1; break;
case 15 : s_tab = 1; break;
case 119: s_home = 1; break;
case 117: s_end = 1; break;
case 132: s_pgup = 1; break;
case 118: s_pgdn = 1; break;
case 115: s_left = 1; break;
case 116: s_right= 1; break;
case 16 : ch = 'Q'; break;
case 17 : ch = 'W'; break;
case 18 : ch = 'E'; break;
case 19 : ch = 'R'; break;
case 20 : ch = 'T'; break;
case 21 : ch = 'Y'; break;
case 22 : ch = 'U'; break;
case 23 : ch = 'I'; break;
case 24 : ch = 'O'; break;
case 25 : ch = 'P'; break;
case 30 : ch = 'A'; break;
case 31 : ch = 'S'; break;
case 32 : ch = 'D'; break;
case 33 : ch = 'F'; break;
case 34 : ch = 'G'; break;
case 35 : ch = 'H'; break;
case 36 : ch = 'J'; break;
case 37 : ch = 'K'; break;
case 38 : ch = 'L'; break;
case 44 : ch = 'Z'; break;
case 45 : ch = 'X'; break;
case 46 : ch = 'C'; break;
case 47 : ch = 'V'; break;
case 48 : ch = 'B'; break;
case 49 : ch = 'N'; break;
case 50 : ch = 'M'; break;
case 129: ch = '0'; break;
case 120: ch = '1'; break;
case 121: ch = '2'; break;
case 122: ch = '3'; break;
case 123: ch = '4'; break;
case 124: ch = '5'; break;
case 125: ch = '6'; break;
case 126: ch = '7'; break;
case 127: ch = '8'; break;
case 128: ch = '9'; break;
case 130: ch = '-'; break;
case 131: ch = '='; break;
case 114: ch = '*'; break;
}
}
if ((keyin.byte.msb != 0) && (!s_alt))
{
switch (keyin.byte.lsb)
{
case 9 : {s_tab = 1;break;}
case 8 : {s_bksp = 1;break;}
case 127 : {s_bksp = 1;break;}
case 27 : {s_esc = 1;break;}
case 13 : {s_enter = 1;break;}
case 255 : break;
default : ch = keyin.byte.lsb;
}
if ((s_tab)||(s_bksp)||(s_esc)||(s_enter)) s_fkey = 1;
}
Exit:
s_ch = ch;
if ((s_enter)&&(s_enterastab)) {s_tab=1;s_enter=0;}
if (s_left) s_leftarrow = 1;
if (s_right) s_rightarrow = 1;
if (s_bksp) s_backspace = 1;
if (s_ins) s_insertkey = 1;
if (s_del) s_deletekey = 1;
}
void S_Get_Field_Value(int s_point)
{
int DecPos,Sign,x,y,z;
double dbl_work,rounding;
s_getfieldtype(s_field->C.s_type[s_point]);
s_decimal = s_ftype;
if (s_decimal > 7)
strcpy(s_editstr,(char*)&S_WorkArea[(int)s_fieldPtr[s_point]]);
else
{
dbl_work = *((double *)(S_WorkArea+s_fieldPtr[s_point]));
if (dbl_work!=0)
{
rounding = (dbl_work<0)?(0-S_Round[s_decimal]):S_Round[s_decimal];
strcpy(s_editstr,(char *)ecvt((dbl_work+rounding),20,&DecPos,&Sign));
while (DecPos<0)
{
s_insert(s_editstr,"0",0,20);
DecPos++;
}
s_insert(s_editstr,".",DecPos,80);
while (s_editstr[0]=='0') s_delete(s_editstr,0,1);
if (Sign) s_insert(s_editstr,"-",0,80);
}
else
strcpy(s_editstr,".000000");
s_editstr[(s_pos(s_editstr,".")+s_decimal)]=0;
if (s_editstr[0]==0)
{
s_editstr[0]='0';
s_editstr[1]=0;
}
x = strlen(s_editstr);
y = x - s_field->C.s_len[s_point];
if (y>0)
while (y--)
{
s_delete(s_editstr,0,1);
x--;
}
s_field->C.s_datalen[s_point] = x;
}
}
void S_PreEdit (int HR, int HL)
{
struct date S_Date;
char workstr[8];
int X,Y,Z;
long rec;
setmem(s_initialvalue,80,0);
setmem(workstr,8,0);
s_userhelp[0]=0;
s_usermask[0]=0;
s_force_editmask=0;
X=0;
while ((HR>0) && (X<3))
{
if (s_vrec!=HR)
{
rec = (long) HR * sizeof(*s_record);
s_vrec = HR;
fseek(s_file,rec,0);
fread(s_indx,sizeof(*s_indx),1,s_file);
}
X++;
Y = s_indx->D.s_rangelist[HL-1][0];
setmem(&s_indx->D.s_rangelist[HL-1][Y+1],78-Y,0);
if (s_indx->D.s_rangelist[HL-1][1]=='H')
{
strcpy(&s_userhelp[0],&s_indx->D.s_rangelist[HL-1][6]);
if (s_autohelp)
strcpy(s_autohelpmsg,s_userhelp);
}
if ((s_indx->D.s_rangelist[HL-1][1]=='E')&&
(s_indx->D.s_rangelist[HL-1][2]=='D'))
if (s_indx->D.s_rangelist[HL-1][6]=='F')
{
s_force_editmask = 1;
strcpy(s_usermask,&s_indx->D.s_rangelist[HL-1][9]);
}
else
{
strcpy(s_usermask,&s_indx->D.s_rangelist[HL-1][7]);
}
if ((s_indx->D.s_rangelist[HL-1][1]=='S')&&
(s_indx->D.s_rangelist[HL-1][2]=='E'))
{
s_indx->D.s_rangelist[HL-1][Y]=0;
strcpy(s_initialvalue,&s_indx->D.s_rangelist[HL-1][6]);
movmem(&s_initialvalue[0],&workstr[0],7);
if (strcmp(strupr(workstr),"SYSDATE")==0)
{
getdate(&S_Date);
X=(int)S_Date.da_mon;
itoa(X,&s_initialvalue[0],10);
if (s_initialvalue[1]==0)
{
s_initialvalue[1]=s_initialvalue[0];
s_initialvalue[0]='0';
}
s_initialvalue[2]='/';
X=(int)S_Date.da_day;
itoa(X,&s_initialvalue[3],10);
if (s_initialvalue[4]==0)
{
s_initialvalue[4]=s_initialvalue[3];
s_initialvalue[3]='0';
}
s_initialvalue[5]='/';
X=(int)S_Date.da_year;
itoa(X,&s_initialvalue[6],10);
}
}
HR = s_indx->D.s_rangerec [HL-1];
HL = s_indx->D.s_rangeline[HL-1];
}
}
void Set_Mask(int L)
{
int X;
X = 0;
s_helppos = -1;
FirstPosition = -1;
LastPosition = -1;
while (X <= L)
{
if (memchr(s_editmasktypes,s_editmask[X],6)==NULL)
s_workstr[X] = s_editmask[X];
else
{
LastPosition = X;
if (s_helppos==-1) s_helppos=X;
if (FirstPosition==-1) FirstPosition=X;
}
X++;
}
}
void Adjust_Pos(int L)
{
int X,
New_Pos;
if (CursorDirection != 0)
{
X = (s_str_pos<-1) ?-1:s_str_pos;
if (!(memchr(s_editmasktypes,s_editmask[X],6)==NULL))
New_Pos = -1;
else
New_Pos = X;
while (New_Pos == -1)
{
X = X + CursorDirection;
if (!(memchr(s_editmasktypes,s_editmask[X],6)==NULL))
New_Pos = X;
else
if ((CursorDirection==-1)&&(X<0))
CursorDirection = 1;
else
if ((CursorDirection==1)&&(X==L))
CursorDirection =-1;
}
s_str_pos = New_Pos;
CursorDirection = 0;
}
}
void s_editstring (int R, int C, int T, int L, int F,
int B, int DF, int DB, int NF, int NB,
char *S)
{
int x,y,z;
char s_curstring[160];
double DoubleWork;
long rec;
if (S_FirstTime) s_init();
if (T > 7)
{
strcpy(s_editmask,s_usermask);
if (s_editmask[0]==0)
{
if (T == 8)
setmem(s_editmask,L,'@');
else
setmem(s_editmask,L,'$');
}
else
if (strlen(s_editmask) < L)
setmem(&s_editmask[strlen(s_editmask)],L-strlen(s_editmask),32);
s_editmask[L]=0;
}
else
s_editmask[0]=0;
if ((s_pos("0.000000",S)==0)||(s_pos(".000000",S)==0)) S[0]=0;
strcpy(s_ins_str," ");
s_attrib = (B*16)+F;
if ((s_cursor==S_OFF)||(s_cursor==S_INVERSEBOLD)||(s_cursor==S_INVERSENORMAL))
{
if (s_attrib > 16)
s_reverse = (F>0)? 15:F;
else
s_reverse = (F==7)? 127:112+F;
}
else
s_reverse = s_attrib;
s_stlabelcolor = S_SetColor(s_stlabelbg,s_stlabelfg);
s_stcolor = S_SetColor(s_stbg,s_stfg);
strcpy(s_workstr,s_blanks);
x = 0;
strcpy(s_workstr,S);
s_workstr[strlen(S)]=32;
s_workstr[L]=0;
s_str_pos = -1;
if (s_editmask[0]!=0)
Set_Mask(L);
else
{FirstPosition=0;
LastPosition= L-1;
s_helppos=0;}
if (S_PosLastChar)
{
x = L-1;
s_str_pos = -2;
while (s_str_pos == -2)
{
if (s_editmask[0]!=0)
{
if (memchr(s_editmasktypes,s_editmask[x],6)==NULL) x--;
else
if (s_workstr[x]==32) x--;
else
s_str_pos = x;
}
else
{
if (s_workstr[x]==32) x--;
else
s_str_pos = x;
}
}
}
else
if (s_nextpos > -1)
s_str_pos = s_nextpos - 1;
else
s_str_pos = -1;
s_nextpos = 0;
if ((s_str_pos == -1)&&
(s_clearifnotrightarrow)&&
(strlen(S)>0))
s_clearnotright = 1;
else
s_clearnotright = 0;
CursorDirection = 1;
s_setcursor(s_cursor);
s_resetkeyflags();
#ifdef MOUSE
while ((!s_enter)&&(!s_tab)&&(!s_esc)&&(!s_fkey)&&(!s_ms->mouseevent))
#else
while ((!s_enter)&&(!s_tab)&&(!s_esc)&&(!s_fkey))
#endif
{
setmem(s_curstring,160,0);
x = 0;
y = 0;
while (x<L)
{
y = (x*2);
s_curstring[y] =s_workstr[x];
s_curstring[y+1] =s_attrib;
x++;
}
if (T<8)
{
s_str_pos += CursorDirection;
if (s_str_pos < 0) s_str_pos=0;
if (s_str_pos >= L) s_str_pos = strlen(s_workstr);
if (s_str_pos >= L) s_str_pos=L-1;
CursorDirection = 0;
}
else
Adjust_Pos(L);
s_curstring[((s_str_pos)*2)+1]=s_reverse;
puttext(C,R,(C-1)+L,R,(char *)&s_curstring);
gotoxy(((C)+s_str_pos),R);
s_lastpos = s_str_pos-1;
S_GetKey();
s_curstring[((s_str_pos)*2)+1]=s_attrib;
puttext(C,R,((C-1)+L),R,(char *)&s_curstring);
if (s_ins)
{
s_ins = 0;
s_fkey = 0;
continue;
}
if ((!s_ctrl)&&(!s_alt))
{
if ((s_left)||(s_bksp))
{
if (s_str_pos > FirstPosition)
{
if (s_bksp) s_del = 1;
CursorDirection = -1;
}
else
{
if (s_left)
{
s_shift = 1;
s_tab = 1;
S_PosLastChar = 1;
}
}
s_left = 0;
s_bksp = 0;
s_fkey = 0;
if (!s_del) continue;
}
if (s_right)
{
if (s_clearnotright)
s_clearnotright = 0;
else
if (s_str_pos < LastPosition)
{
if (T>7) CursorDirection = 1;
else
{
if (!(s_str_pos<(s_strlen(s_workstr)-1)))
s_tab = 1;
else CursorDirection = 1;
}
}
else
s_tab = 1;
s_shift = 0;
s_right = 0;
s_fkey = 0;
continue;
}
if (s_del)
{
if (s_strlen(s_workstr)>-1)
{
if (s_clearnotright)
s_clearnotright = 0;
if (s_shift)
{
setmem(&s_workstr[s_str_pos],(L-s_str_pos)+1,32);
if (s_editmask[0]>0) Set_Mask(L);
}
else
{
z = FirstPosition;
if (CursorDirection==-1)
{
x = s_str_pos;
z = s_str_pos-1;
if (T>7)
while ((z>=FirstPosition)&&
(memchr(s_editmasktypes,s_editmask[z],6)==NULL))
z--;
}
if (z>=FirstPosition)
{
if ((s_str_pos<L)&&(s_editmask[0]))
{
if (CursorDirection!=-1)
{
x = s_str_pos+1;
z = s_str_pos;
}
while (x < L)
{
if (memchr(s_editmasktypes,s_editmask[x],6)!=NULL)
{
if (s_editmask[x] != s_editmask[z])
{
s_workstr[z] = 32;
x = L;
}
else
{
s_workstr[z] = s_workstr[x];
z++;
while (memchr(s_editmasktypes,s_editmask[z],6)==NULL) z++;
}
}
x++;
}
if (x >= L) s_workstr[z] = 32;
}
else
{
s_delete(s_workstr,(s_str_pos+CursorDirection),1);
strcat(s_workstr," ");
}
}
}
}
s_fkey = 0;
continue;
}
if ((s_str_pos==s_helppos)&&(s_ch=='?'))
{
if (s_userhelp[0]==0)
strcpy(s_autohelpmsg," No HELP available for this field. ");
else
strcpy(s_autohelpmsg,s_userhelp);
s_ch = 0;
}
if ((s_ch > 31)&&(s_ch < 128))
{
if (T<8)
{
if (((s_ch=='-')&&(s_str_pos>0))||
((s_ch=='.')&&(T==0))||
((s_ch!='.')&&(s_ch!='-')&&(!isdigit(s_ch))))
s_ch = 0;
if ((s_ch=='.')&&(strchr(s_workstr,'.')))
{
y=0;
x=0;
z=0;
while (y < L)
{
if (y==s_str_pos) s_newstr[y++]='.';
else
if (s_workstr[x]=='.') x++;
else
{
s_newstr[y] = s_workstr[x];
x++;
y++;
}
}
CursorDirection = 1;
s_ch = 0;
strcpy(s_workstr,s_newstr);
}
if (s_ch==0)
strcpy(s_errormsg,s_numericfieldmsg);
}
if (T==8)
{
if (!isalpha(s_ch))
{
if (s_editmask[0]>0)
{
if ((s_editmask[s_str_pos-1]=='@')||
(s_editmask[s_str_pos-1]=='2'))
{
s_ch = 0;
strcpy(s_errormsg,s_alphamaskmsg);
}
}
else
if (s_ch!=32)
{
s_ch = 0;
strcpy(s_errormsg,s_alphafieldmsg);
}
}
}
if ((T==9)&&(s_editmask[0]>0))
{
if ((s_editmask[s_str_pos]=='@')||(s_editmask[s_str_pos]=='2'))
{
if (!isalpha(s_ch))
{
strcpy(s_errormsg,s_alphamaskmsg);
s_ch =0;
}
}
if ((s_editmask[s_str_pos]=='#')||(s_editmask[s_str_pos]=='3'))
{
if (!isdigit(s_ch))
{
strcpy(s_errormsg,s_numericmaskmsg);
s_ch=0;
}
}
}
if (s_ch>0)
{
if ((s_clearnotright)&&(s_str_pos==FirstPosition))
{
setmem(s_workstr,L,32);
s_clearnotright = 0;
if (s_editmask[0]) Set_Mask(L);
}
if (s_insertmode)
{
if (s_str_pos <= LastPosition)
{
if (s_editmask[0]>0)
{
y = 0;
x = s_str_pos;
z = x;
while (((memchr(s_editmasktypes,s_editmask[x],6)==NULL)||
(s_editmask[x]==s_editmask[z]))&&(x < L)) x++;
y = x-1;
while (!(y<s_str_pos))
{
if (memchr(s_editmasktypes,s_editmask[y],6)==NULL) y--;
else
if ((s_editmask[z]!=s_editmask[x])||
(memchr(s_editmasktypes,s_editmask[x],6)==NULL))
{x--;y=x-1;}
else
{
s_workstr[x]=s_workstr[y];
x--;
y--;
}
}
s_workstr[s_str_pos] = s_ch;
}
else
{
s_ins_str[0]=s_ch;
s_ins_str[1]=0;
s_insert(s_workstr,s_ins_str,(s_str_pos),L);
s_workstr[L]=0;
}
if (s_str_pos < LastPosition)
CursorDirection = 1;
else
{
if (s_tabatendoffield) s_tab =1;
s_shift=0;
}
}
}
else
{
s_workstr[s_str_pos]=s_ch;
if (s_str_pos < LastPosition)
CursorDirection=1;
else
{
if (s_tabatendoffield) s_tab =1;
s_shift=0;
}
}
}
}
if ((!s_enter)&&(s_tab))
{
if ((s_shift)&&(s_str_pos>0))
{
x=s_str_pos-1;
s_str_pos=0;
if ((x>0)&&(s_editmask[0]>0))
{
if (memchr(s_editmasktypes,s_editmask[x],6)!=NULL)
while ((x>-1)&&(memchr(s_editmasktypes,s_editmask[x],6)!=NULL))
x--;
while ((x>-1)&&(memchr(s_editmasktypes,s_editmask[x],6)==NULL))
x--;
while ((x>-1)&&(memchr(s_editmasktypes,s_editmask[x],6)!=NULL))
x--;
s_str_pos = x+1;
}
s_tab=0;
s_fkey=0;
}
if ((!s_shift)&&(s_str_pos<L))
{
if (s_editmask[0]>0)
{
x = s_str_pos;
while ((x<L-1)&&(memchr(s_editmasktypes,s_editmask[x],6)!=NULL))
x++;
while ((x<L-1)&&(memchr(s_editmasktypes,s_editmask[x],6)==NULL))
x++;
if (x<(L-1))
{
s_str_pos = x;
s_tab=0;
s_fkey=0;
}
}
}
}
if (s_force_editmask)
{
if ((s_enter)||(s_tab))
{
x = -1;
while (x < L)
{
x++;
if ((!(memchr(s_editmasktypes,s_editmask[x],4)==NULL))&&
(s_workstr[x]==32))
{
s_str_pos = x;
strcpy(s_errormsg,"'");
s_errormsg[0]=39;
s_errormsg[1]=s_ch;
s_errormsg[2]=0;
strcat(s_errormsg,"' does not fit edit mask ");
strcat(s_errormsg,s_editmask);
s_enter= 0;
s_tab = 0;
s_fkey = 0;
x = L;
}
}
}
}
}
}
s_setcursor(S_OFF);
strcpy(s_editstr,s_workstr);
if (s_strlen(s_workstr)>-1) s_editstr[s_strlen(s_workstr)-1]=0;
if (T<8)
{
y=strlen(s_editstr);
while ((y>0)&&(s_editstr[y-1]<33))
{
s_editstr[y-1]=0;
y--;
}
if (strchr(s_editstr,'.')==NULL) strcat(s_editstr,".000000");
else strcat(s_editstr,"000000");
s_editstr[s_pos(s_editstr,".")+T]=0;
s_str_pos = (s_editstr[0]=='-')?1:0;
while ((s_editstr[0]==32)||(strlen(s_editstr)>L))
s_delete(s_editstr,s_str_pos,1);
if (strcmp("-",s_editstr)==0) s_editstr[0]=0;
if (s_editstr[0]==0)
{
s_editstr[0]='0';
s_editstr[1]=0;
}
}
if (s_editmask[0]>0)
{
y=0;
for (x=0;((x<L)&&(y==0));x++)
{
if ((s_editstr[x]>32)&&(memchr(s_editmasktypes,s_editmask[x],6)!=NULL))
y++;
}
if (y==0) setmem(s_editstr,L,0);
}
else
{
x = L-1;
while ((x>-1)&&(s_editstr[x]<33)) s_editstr[x--]=0;
}
setmem(s_autohelpmsg,81,0);
setmem(s_editmask,81,0);
movmem(s_editstr,s_newstr,L+1);
movmem(s_editstr,S,L+1);
s_displayscreenfield(R,C,T,L,strlen(s_newstr),DF,DB,NF,NB,s_newstr);
movmem(s_newstr,s_editstr,L+1);
}
unsigned char s_setdisplayon(int X)
{
int Y,Z;
if (X < 0) return 4;
else
{
Y=0;
for (Z=0;Z<s_curr.s_count;Z++)
if (s_field->C.s_type[Z]<10) Y++;
if (Y==0) return 1;
else
if (X>s_curr.s_count) return 2;
else
if (s_field->C.s_type[X] > 19) return 3;
else
if (s_field->C.s_type[X] < 20)
{
s_field->C.s_type[X] += 90;
return 0;
}
else
return 0;
}
}
unsigned char s_setdisplayoff(int X)
{
if (X < 0) return 4;
else
if (X>s_curr.s_count) return 1;
else
if (s_field->C.s_type[X] < 20) return 3;
else
{
if (s_field->C.s_type[X] > 19)
s_field->C.s_type[X] -= 90;
return 0;
}
}
unsigned char s_isdupe(int S_Index)
{
if (((S_Index > -1)&&(S_Index < s_curr.s_count))&&
(((s_field->C.s_type[S_Index]>=10) &&(s_field->C.s_type[S_Index]<=19))||
((s_field->C.s_type[S_Index]>=100)&&(s_field->C.s_type[S_Index]<=109))))
return 1;
else
return 0;
}
unsigned char s_setdupe(int S_Index)
{
int X,Y;
Y = 0;
s_setdupefields = 0;
for (X=0;X<s_curr.s_count;X++)
if (s_field->C.s_type[X]<10) Y++;
if ((!((S_Index > -1)&&(S_Index < s_curr.s_count)))||
(((s_field->C.s_type[S_Index]>=10) &&(s_field->C.s_type[S_Index]<=19))||
((s_field->C.s_type[S_Index]>=100)&&(s_field->C.s_type[S_Index]<=109))))
{
s_field->C.s_type[S_Index] -=10;
return 0;
}
else
{
if ((Y > 1)||(s_field->C.s_type[S_Index]>9))
{
s_field->C.s_type[S_Index] +=10;
if (s_field->C.s_type[S_Index] < 20) s_setdupefields = 1;
return 1;
}
else
{
strcpy(s_errormsg,"At least one field must remain a data entry field.");
return 0;
}
}
}
void s_resetdupe(int S_Index)
{
if (((S_Index > -1)&&(S_Index <s_curr.s_count))||
(((s_field->C.s_type[S_Index]>=10) &&(s_field->C.s_type[S_Index]<=19))||
((s_field->C.s_type[S_Index]>=100)&&(s_field->C.s_type[S_Index]<=109))))
s_field->C.s_type[S_Index]-=10;
}
void s_cleardupes()
{
int S_Index;
S_Index = 0;
while (S_Index < s_curr.s_count)
{
if (((s_field->C.s_type[S_Index]>=10) &&(s_field->C.s_type[S_Index]<=19))||
((s_field->C.s_type[S_Index]>=100)&&(s_field->C.s_type[S_Index]<=109)))
s_setdupe(S_Index);
S_Index++;
}
}
void s_clearscreen(int Initialize)
{
int X;
double *RealWork, WorkVal;
setmem(s_workstr,81,0);
s_initialvalue[0]=0;
for (X=0;X<s_curr.s_count;X++)
{
s_getfieldtype(s_field->C.s_type[X]);
if (Initialize)
S_PreEdit(
s_field->C.s_rangenextrec[X],
s_field->C.s_rangenextline[X]);
if (!s_duptype)
{
if (s_ftype < 8)
{
WorkVal = atof(s_initialvalue);
RealWork = (double *)(S_WorkArea+s_fieldPtr[X]);
*RealWork= WorkVal;
}
else
{
setmem(S_WorkArea+s_fieldPtr[X],s_field->C.s_len[X]+1,0);
strcpy((char *)S_WorkArea+s_fieldPtr[X],s_initialvalue);
}
}
}
}
void s_refreshscreen()
{
if (s_delayed) s_delayed = 0;
puttext(1,1,80,24,&s_record->B.s_video[0]);
S_FillScreen();
}
#ifdef COLORCHANGE
unsigned char s_changescreencolor(
int Control,
int Bg,
int Fg,
int StartRow,
int EndRow,
int StartCol,
int EndCol)
{
unsigned char Row, Col, Ch, Color;
int F,P;
if (Control > 4) return 1;
else
if (Bg>7) return 2;
else
if (Fg>30) return 3;
else
if ((StartRow < 1)||(StartRow>24)) return 4;
else
if ((EndRow<StartRow)||(EndRow>24)) return 5;
else
if ((StartCol < 1)||(StartCol>80)) return 6;
else
if ((EndCol<StartCol)||(EndCol>80)) return 7;
else
{
F=0;
Row=StartRow;
Col=StartCol;
if (Control!=4)
Color = S_SetColor(Bg,Fg);
while ((F<s_curr.s_count)&&(s_field->C.s_row[F] < Row)) F++;
while ((F<s_curr.s_count)&&
((s_field->C.s_col[F])+(s_field->C.s_len[F]+1))<Col) F++;
if (!(F<s_curr.s_count)) F=-1;
do
{
if (F>-1)
{
while(
(F>-1)&&
(Row==s_field->C.s_row[F])&&
(Col>((s_field->C.s_col[F])+(s_field->C.s_len[F]+1))))
{
F =(F<s_curr.s_count) ? F+1:-1;
}
while(
(F>-1)&&
(Row>=s_field->C.s_row[F])&&
(Col>=s_field->C.s_col[F])&&
(Col<=((s_field->C.s_col[F])+(s_field->C.s_len[F]+1))))
{
Col = ((s_field->C.s_col[F])+(s_field->C.s_len[F]+1));
F++;
if (Col>EndCol) {Row++; Col=StartCol;}
if (Row>s_field->C.s_row[F])
while ((F<s_curr.s_count)&&(Row>s_field->C.s_row[F])) F++;
while((Row==s_field->C.s_row[F])&&
(StartCol>((s_field->C.s_col[F])+(s_field->C.s_len[F]+1)))) F++;
if (!(F<s_curr.s_count)) F=-1;
}
}
if ((Row <= EndRow)&&(Col <=EndCol))
{
P=((Row-1)*160)+((Col-1)*2)+1;
Ch= s_record->B.s_video[P-1];
switch (Control)
{
case 0 :
{s_record->B.s_video[P]=Color;break;}
case 1 :
{
switch (Ch)
{
case 179:
case 180:
case 191:
case 192:
case 193:
case 194:
case 195:
case 196:
case 197:
case 217:
case 218:{s_record->B.s_video[P]=Color;break;}
}
break;
}
case 2 :/* Double Lines */
{
switch (Ch)
{
case 181:
case 182:
case 183:
case 184:
case 185:
case 186:
case 187:
case 188:
case 189:
case 190:
case 198:
case 199:
case 200:
case 201:
case 202:
case 203:
case 204:
case 205:
case 206:
case 207:
case 208:
case 209:
case 210:
case 211:
case 212:
case 213:
case 214:
case 215:
case 216:{s_record->B.s_video[P]=Color;break;}
}
break;
}
case 3 :/* Bold Chars */
{
switch (Ch)
{
case 219:
case 220:
case 221:
case 222:
case 223:{s_record->B.s_video[P]=Color;break;}
}
break;
}
case 4 :/* Change all color attribs (Bg) to (Fg) */
{ if (s_record->B.s_video[P]==Bg)
s_record->B.s_video[P]=Fg;
break;
}
}
}
Col++;
if (Col>EndCol) {Row++;Col=StartCol;}
}
while (Row<=EndRow);
return 0;
}
}
unsigned char s_changefieldcolor(
int Field,
int set,
int Bg,
int Fg)
{
if (Field>s_curr.s_count) return 1;
else
if (set>2) return 2;
else
if (Bg>7) return 3;
else
if (Fg>30) return 4;
else
{
switch (set)
{
case 0 :
{s_field->C.s_normalbg[Field]=Bg;
s_field->C.s_normalfg[Field]=Fg;
break;}
case 1 :
{s_field->C.s_promptbg[Field]=Bg;
s_field->C.s_promptfg[Field]=Fg;
break;}
case 2 :
{s_field->C.s_displaybg[Field]=Bg;
s_field->C.s_displayfg[Field]=Fg;
break;}
}
return 0;
}
}
void s_storecolorchanges()
{
char hold[16];
int A,B,C,X,Y,Z;
int RR;
long rec;
if (s_curr.s_fieldsrecno)
{
s_firstfield = (s_curr.s_first)-1;
s_point = 0;
for (X=0;X<s_curr.s_count;X++)
{
Z = ((s_field->C.s_col[X])-1)*2;
A = ((s_field->C.s_col[X]-1)+s_field->C.s_len[X])*2;
B = (s_field->C.s_row[X]-1)*160;
s_record->B.s_video[B+Z]='[';
s_record->B.s_video[B+A]=']';
C = 0;
Z = s_field->C.s_col[X]*2;
while (C<15)
{
if (s_field->C.s_fieldname[X][C] > 32)
{
s_record->B.s_video[B+Z] = s_field->C.s_fieldname[X][C];
}
else
C=99;
Z+=2;
C++;
}
movmem(&s_field->C.s_fieldname[X][0],hold,16);
movmem(hold,&s_field->C.s_fieldname[X][1],16);
s_field->C.s_fieldname[X][0]=0;
Z = 1;
while (Z<17)
{
if (s_field->C.s_fieldname[X][Z]>32)
{
s_field->C.s_fieldname[X][0]++;
Z++;
}
else
Z=99;
}
}
rec = (long) (s_curr.s_fieldsrecno)*sizeof(*s_record);
C=fseek(s_file,rec,0);
C=fwrite((void *)s_field,sizeof(*s_field),1,s_file);
}
rec = (long) (s_curr.s_recordnumber)*sizeof(*s_record);
C=fseek(s_file,rec,0);
C=fwrite((void *)s_record,sizeof(*s_record),1,s_file);
s_loadscreen(s_curr.s_name);
}
#endif
#ifdef VALIDATE
#include "Validate.C"
#endif
void s_nextkey()
{
if (S_FirstTime) s_init();
s_errormsg[0]=0;
s_usermsg[0]=0;
s_autohelpmsg[0]=0;
s_wait=1;
S_GetKey();
}
void s_readkey()
{
if (S_FirstTime) s_init();
if (s_delayed) s_refreshscreen();
if (s_curr.s_count > 0) S_FillScreen();
s_stlabelcolor = S_SetColor(s_stlabelbg,s_stlabelfg);
s_stcolor = S_SetColor(s_stbg,s_stfg);
S_GetKey();
}
void s_readfield()
{
double *Dbl;
int x,y;
if (S_FirstTime) s_init();
if (s_delayed) s_refreshscreen();
if (s_curr.s_count > 0) S_FillScreen();
if ((s_point < 0)||(s_point > s_curr.s_count))
{
strcpy(s_errormsg," Field number in s_point is out of range ");
s_readkey();
goto Exit_Proc;
}
if ((s_field->C.s_type[s_point]>89)&&(s_field->C.s_type[s_point]<110))
{
strcpy(s_errormsg," Cannot read a DISPLAY only field - Any key to continue ");
s_readkey();
goto Exit_Proc;
}
if ((s_field->C.s_type[s_point]>9)&&(s_field->C.s_type[s_point]<20))
{
if (!s_setdupefields)
{
strcpy(s_errormsg," Invalid access of dupe (repeating) field - Any key to Continue");
s_readkey();
goto Exit_Proc;
}
};
if (s_setdupefields) s_setdupefields = 0;
s_prevfield = s_point;
s_screenvalid = 0;
s_resetkeyflags();
#ifdef MOUSE
while ((!s_ms->mouseevent)&&(!s_screenvalid)&&(!s_fkey))
#else
while ((!s_screenvalid)&&(!s_fkey))
#endif
{
S_Get_Field_Value(s_point);
s_getfieldtype(s_field->C.s_type[s_point]);
#ifdef MOUSE
while ((!s_ms->mouseevent)&&(!s_enter)&&(s_prevfield == s_point)&&(!s_fkey))
#else
while ((!s_enter)&&(s_prevfield == s_point)&&(!s_fkey))
#endif
{
S_PreEdit(
s_field->C.s_rangenextrec[s_point],
s_field->C.s_rangenextline[s_point]);
s_editstring(
s_field->C.s_row[s_point],
s_field->C.s_col[s_point],
s_ftype,
s_field->C.s_len[s_point],
s_field->C.s_promptfg[s_point],
s_field->C.s_promptbg[s_point],
s_field->C.s_displayfg[s_point],
s_field->C.s_displaybg[s_point],
s_field->C.s_normalfg[s_point],
s_field->C.s_normalbg[s_point],
s_editstr);
s_field->C.s_datalen[s_point] = strlen(s_editstr);
if (s_ftype<8)
{
x=0;
y=0;
while (s_editstr[x]!=0) if (s_editstr[x++]=='.') {y=1;break;};
if (y==0)
strcat(s_editstr,".0 ");
else
strcat(s_editstr,"0 ");
Dbl = (double *)(S_WorkArea+s_fieldPtr[s_point]);
*Dbl=atof(s_editstr);
}
else
{
y=strlen(s_editstr);
while ((y>0)&&(s_editstr[y-1]<33))
{
s_editstr[y-1]=0;
y--;
}
strcpy((char *)S_WorkArea+s_fieldPtr[s_point],s_editstr);
}
if (s_tab) s_fkey = 1;
}
s_point = s_prevfield;
if ((s_tab)||(s_enter)||(s_leftarrow)||(s_rightarrow))
{
#ifdef VALIDATE
if (s_field->C.s_rangenextrec[s_point]>0)
{
s_validatefield = s_point;
s_validatescreen();
s_validatefield = 0;
s_prevfield = s_point;
if (!s_screenvalid) s_resetkeyflags();
}
else
#endif
if ((strlen(s_editstr) > s_field->C.s_len[s_point])||(s_enter))
s_screenvalid = 1;
}
}
Exit_Proc:
delay(0);
}
void s_readscreen()
{
int x,y;
double *Dbl;
if (S_FirstTime) s_init();
if (s_delayed) s_refreshscreen();
switch (s_curr.s_compiledind)
{
case 1 :
{s_readkey();break;}
case 2 :
{s_readkey();break;}
case 3 :
{
s_screenvalid = 0;
s_validatefield = -1;
do
{
S_FillScreen();
if (s_point < 0) s_prevfield = 9999;
s_direction = 1;
if ((s_point > s_curr.s_count)||(s_point < 0))
s_point = s_curr.s_count-1;
else
s_prevfield = s_point;
do
{
if ((s_field->C.s_type[s_point]>19)||
((!s_setdupefields)&&(s_field->C.s_type[s_point] > 9)))
{
s_prevfield = -1;
do
{
s_point = (s_direction > 0) ?
s_field->C.s_next[s_point]-1 : s_field->C.s_prev[s_point]-1;
s_getfieldtype(s_field->C.s_type[s_point]);
if ((s_entrytype)||
((!s_disptype)&&((s_duptype)&&(s_direction== -1))))
s_prevfield = s_point;
}
while (s_prevfield == -1);
}
else
s_setdupefields = 0;
s_prevfield = s_point;
S_Get_Field_Value(s_point);
s_direction = 1;
S_PreEdit(
s_field->C.s_rangenextrec[s_point],
s_field->C.s_rangenextline[s_point]);
s_editstring(
s_field->C.s_row[s_point],
s_field->C.s_col[s_point],
s_ftype,
s_field->C.s_len[s_point],
s_field->C.s_promptfg[s_point],
s_field->C.s_promptbg[s_point],
s_field->C.s_displayfg[s_point],
s_field->C.s_displaybg[s_point],
s_field->C.s_normalfg[s_point],
s_field->C.s_normalbg[s_point],
s_editstr);
s_field->C.s_datalen[s_point] = strlen(s_editstr);
if ((s_enterafterfield > -1)&&
(s_enterafterfield == s_point))
s_enter = 1;
if (s_ftype < 8)
{
x=0;
y=0;
while (s_editstr[x]!=0) if (s_editstr[x++]=='.') {y=1;break;};
if (y==0)
strcat(s_editstr,".0 ");
else
strcat(s_editstr,"0 ");
Dbl = (double *)(S_WorkArea+s_fieldPtr[s_point]);
*Dbl=atof(s_editstr);
}
else
{
y=strlen(s_editstr);
while ((y>0)&&(s_editstr[y-1]<33))
{
s_editstr[y-1]=0;
y--;
}
strcpy((char *)S_WorkArea+s_fieldPtr[s_point],s_editstr);
}
#ifdef VALIDATE
if ((s_autovalidate)&&(!s_enter))
{
if (s_field->C.s_rangenextrec[s_point] > 0)
{
s_validatefield = s_point;
s_validatescreen();
s_validatefield = -1;
if (!s_screenvalid)
{
s_tab = 0;
s_enter = 0;
}
}
}
#endif
if ((s_enterafterfield > -1)&&
(s_enterafterfield==s_point))
s_enter = 1;
if (s_tab)
{
s_direction = (s_shift) ? -1:1;
s_point = (s_direction > 0)
? (s_field->C.s_next[s_point]-1): (s_field->C.s_prev[s_point]-1);
if ((s_shift)&&
(s_field->C.s_type[s_point]>9)&&
(s_field->C.s_type[s_point]<20)) s_setdupefields = 1;
s_fkey = 0;
s_shift = 0;
}
}
#ifdef MOUSE
while ((!s_ms->mouseevent) && (!s_enter) && (!s_fkey));
#else
while ((!s_enter) && (!s_fkey));
#endif
#ifdef VALIDATE
if (s_enter)
{
s_validatefield = -1;
s_validatescreen();
if (!s_screenvalid) s_fkey = 0;
}
else
#endif
s_screenvalid = 1;
}
#ifdef MOUSE
while ((!s_ms->mouseevent) && (!s_screenvalid) && (!s_fkey));
#else
while ((!s_screenvalid) && (!s_fkey));
#endif
}
}
}